package com.kgc.project.projectweb.controller;

import com.github.pagehelper.PageInfo;
import com.kgc.project.entity.Projectinfo;
import com.kgc.project.service.ProjectinfoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class ProjectController {
    @Reference
    ProjectinfoService projectinfoService;

    @RequestMapping("/selectPro")
    @ResponseBody
    public PageInfo<Projectinfo> selsect(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "status",defaultValue = "0")Integer status){
        PageInfo<Projectinfo> projectinfoPageInfo = projectinfoService.selectAll(pageNum, status);
        return projectinfoPageInfo;
    }

    @RequestMapping("/selectById")
    @ResponseBody
    public  Projectinfo selectById(Integer id){
        Projectinfo projectinfo = projectinfoService.selectById(id);
        return projectinfo;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(@RequestBody Projectinfo projectinfo){
        Map<String,Object> map=new HashMap<>();
        int i = projectinfoService.updateProject(projectinfo);
        if (i>0) {
            map.put("result","success");
            return map;
        }else {
            map.put("result","error");
            return map;
        }
    }
}
